package cn.itcast.bos.web.action.system;

import cn.itcast.bos.domain.system.Permission;
import cn.itcast.bos.service.system.PermissionService;
import cn.itcast.bos.web.action.common.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: SOS
 * @create: 2018-03-12 21:38
 */
@ParentPackage("json-default")
@Namespace("/")
@Controller
@Scope("prototype")
public class PermissionAction extends BaseAction<Permission> {

    @Autowired
    private PermissionService permissionService;

    /**
     * 权限数据表的查询所有功能
     * @return
     */
    @Action(value = "permission_list", results = {@Result(name = SUCCESS, type = "json"),
            @Result(name = "input", location = "./pages/system/menu.html", type = "redirect")})
    public String permissionList(){

        List<Permission> permissions = permissionService.findAll();
        ActionContext.getContext().getValueStack().push(permissions);
        return SUCCESS;
    }

    @Action(value = "permission_save", results = {@Result(name = SUCCESS, location = "./pages/system/menu.html", type = "redirect"),
            @Result(name = "input", location = "./pages/system/menu.html", type = "redirect")})
    public String permissionSave(){
        permissionService.save(model);
        return SUCCESS;
    }

}
